<?php

namespace common\model;

use think\model\RelationModel;

class ProjectDelayReviewWorkflowRelationModel extends RelationModel
{

    //自动验证
    protected $_validate = [
        ['review_workflow_id', '', '', self::EXISTS_VALIDATE, 'require'],
        ['step_category_id', '', '', self::EXISTS_VALIDATE, 'require'],
        ['project_id', '', '', self::EXISTS_VALIDATE, 'require'],

        ['review_workflow_id', '', '', self::EXISTS_VALIDATE, 'integer'],
        ['step_category_id', '', '', self::EXISTS_VALIDATE, 'integer'],
        ['project_id', '', '', self::EXISTS_VALIDATE, 'integer'],
    ];

    //自动完成
    protected $_auto = [
        ['uuid', 'create_uuid', self::MODEL_INSERT, 'function'],
        ['review_node_config', 'json_encode', self::EXISTS_VALIDATE, 'function']
    ];

    protected $_validate_after_auto = [
        ['project_id,step_workflow_id,step_category_id,attr_str', '', '', self::MODEL_INSERT, 'unique'],
    ];

    /**
     * 审核配置
     * @param $value
     * @return array|mixed
     */
    public function getReviewNodeConfigAttr($value)
    {
        if (!empty($value)) {
            return json_decode($value, true);
        }
        return [];
    }
}
